int TreeSize(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    return TreeSize(root->left) + TreeSize(root->right) + 1;
}
void preorder(int* arr, int* n, struct TreeNode* root)
{
    if (root == NULL)
        return;
    arr[*n] = root->val;
    (*n)++;
    preorder(arr, n, root->left);
    preorder(arr, n, root->right);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    int count = TreeSize(root);
    int* arr = (int*)malloc(sizeof(int) * count);
    int n = 0;
    preorder(arr, &n, root);
    *returnSize = count;
    return arr;
}